package com.usian.behavior.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.behavior.mapper.ApBehaviorEntryMapper;
import com.usian.behavior.service.ApBehaviorEntryService;
import com.usian.model.behavior.pojos.ApBehaviorEntry;
import org.springframework.stereotype.Service;

@Service
public class ApBehaviorEntryServiceImpl
        extends ServiceImpl<ApBehaviorEntryMapper, ApBehaviorEntry>
        implements ApBehaviorEntryService {


    @Override
    public ApBehaviorEntry queryEntryByUserIdOrEquipmentId(Integer userId, Integer equipmentId) {

        if (userId != null) {
            ApBehaviorEntry apBehaviorEntry =
                    getOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, userId).eq(ApBehaviorEntry::getType, ApBehaviorEntry.Type.USER.getCode()));
            return apBehaviorEntry;
        }

        if (equipmentId != null) {
            ApBehaviorEntry apBehaviorEntry =
                    getOne(Wrappers.<ApBehaviorEntry>lambdaQuery().eq(ApBehaviorEntry::getEntryId, equipmentId).eq(ApBehaviorEntry::getType, ApBehaviorEntry.Type.EQUIPMENT.getCode()));
            return apBehaviorEntry;
        }

        return null;
    }
}
